﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Youz.Common.Entity;
using Youz.CreditRepay.DAL;
using Youz.CreditRepay.Entity;

namespace Youz.CreditRepay.BLL
{
    /// <summary>
    /// Member_Certified BLL Class
    /// </summary>
    public partial class Member_CertifiedBLL : BaseBLL
    {
        Member_CertifiedDAL dal;

        public Member_CertifiedBLL()
        {
            dal = new Member_CertifiedDAL();
        }

        #region  成员方法
        /// <summary>
        ///  新增一条数据
        /// </summary>
        public bool Add(Member_Certified model)
        {
            return dal.Add(model);
        }

        /// <summary>
        ///  保存一条数据
        /// </summary>
        public bool Update(Member_Certified model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        ///</summary>
        public bool Delete(Guid CertifiedID)
        {
            return dal.Delete(CertifiedID);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Member_Certified Get(Guid CertifiedID)
        {
            return dal.Get(CertifiedID);
        }

        public Member_Certified Get(string memberAccount)
        {
            return dal.Get(memberAccount);
        }

        /// <summary>
        /// 得到一个JSON对象
        /// </summary>
        public string GetJson(Guid CertifiedID)
        {
            return Core.GetJsonByObject(Get(CertifiedID));
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet Gets(string sqlWhere)
        {
            return dal.Gets(sqlWhere);
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet Gets(int top, string sqlWhere, string filedOrder)
        {
            return dal.Gets(top, sqlWhere, filedOrder);
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string sqlWhere)
        {
            return dal.GetRecordCount(sqlWhere);
        }

        /// <summary>
        /// 获得数据列表分页
        /// </summary>
        public DataTable Gets(string sqlWhere, int pageindex, int pagesize, out int total, params SqlParameter[] cmdParms)
        {
            return dal.Gets(sqlWhere, pageindex, pagesize, out total, cmdParms);
        }
        #endregion  成员方法

        #region  新增
        /// <summary>
        ///撤销申请
        /// </summary>
        public bool Cancel(Member_Certified model)
        {
            return dal.Cancel(model);
        }

        /// <summary>
        /// 审核
        /// </summary>
        public bool Audit(Member_Certified model)
        {
            return dal.Audit(model);
        }

        /// <summary>
        /// 得到一个对象实体(获取该用户最后一次认证数据)
        /// </summary>
        public Member_Certified GetCertified(string MemberAccount)
        {
            return dal.GetCertified(MemberAccount);
        }

        public AuditStatus GetStatus(string MemberAccount)
        {
            var mc = GetCertified(MemberAccount);

            return mc == null ? AuditStatus.Unknown : mc.Status;
        }

        /// <summary>
        /// 用户的姓名是否通过认证
        /// </summary>
        /// <param name="memberAccount"></param>
        /// <param name="fullName"></param>
        /// <returns></returns>
        public bool IsCertified(string memberAccount, string fullName)
        {
            Member_Certified mc = GetCertified(memberAccount);

            if (mc == null)
                return false;
            else
                return mc.Name == fullName;
        }

        public bool IsCertified(string memberAccount)
        {
            Member_Certified mc = GetCertified(memberAccount);

            if (mc != null)
            {
                return mc.Status == AuditStatus.Pass;
            }
            else
            {
                return false;
            }
        }
        #endregion
    }
}
